home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_053 / arp / filenote / filenote.asm < prev    next >
Assembly Source File  |  1992-05-06  |  5KB  |  147 lines

  1. ;
  2. ; FileNote.asm
  3. ;
  4. ; Written: Jan/10/1987 by SDB
  5. ; Copyright (c) 1987 by Scott Ballantyne.
  6. ;
  7. ;       This program may be freely distributed.  Improvements are welcome,
  8. ;       but any code based on this program can never become proprietary.
  9. ;       You are welcome to use, improve, and distribute this program.
  10. ;       You are forbidden to prevent anyone else from using, improving,
  11. ;       or distributing this program. 
  12. ;       
  13. ;       Another contribution to Cheath's replace AmigaDOS commands.  Be the
  14. ;       first on YOUR block to own the entire set.
  15. ;
  16. ;       With the manx assembler, this comes in at 388 bytes.  Metacompost's
  17. ;       assembler should bring this in about 72 bytes less.  The BCPL version
  18. ;       is 700 bytes...
  19. ;
  20. ;       Syntax is the essentially the same as the BCPL version, but quotes
  21. ;       are optional, unless, of course, the filename has spaces.
  22. ;
  23. ;       filenote ["]<filename>["] ["]<comment>["]
  24. ;
  25. ;       As in the BCPL version, filename by itself deletes the comment, if
  26. ;       any, as does Filenote filename "".  Actually, I don't know if that
  27. ;       works in the BCPL one.
  28. ;
  29. ;       Tried to be a little more informative in usage and error messages.
  30. ;
  31. LIBRARY_VERSION         equ     31
  32.  
  33. _LVOOpenLibrary         equ     -552
  34. _LVOCloseLibrary        equ     -414
  35. _AbsExecBase            equ     4
  36. _LVOOutput              equ     -60
  37. _LVOWrite               equ     -48
  38. _LVOSetComment          equ     -180
  39.  
  40.         entry   Start
  41.         rts
  42. Start:
  43.         move.l  a0,a2           ; save command ptr
  44.         move.l  _AbsExecBase,a6
  45.         lea     DOSName(pc),a1
  46.         moveq.l #LIBRARY_VERSION,d0
  47.         jsr     _LVOOpenLibrary(a6)
  48.         bne.s   okok
  49.         move.l  #20,d0          ; openlibrary didn't...
  50.         rts
  51. okok:
  52.         move.l  d0,a6           ; doslib ptr in a6
  53.         move.b  #' ',d7         ; initial terminator character for filename
  54.         bsr.s   getcmd          ; get filename in a3
  55.         tst.l   d0              ; returns length in d0
  56.         bne.s   okokok
  57.         lea     usage(pc),a0
  58.         bra.s   error
  59. okokok: move.l  a0,d1           ; Setup for setcomment
  60.         lea     null(pc),a0     ; potential NULL comment
  61.         cmp.b   #$0a,d6
  62.         beq.s   setcom          ; use null comment
  63. getcom: moveq   #$0a,d7         ; Scan to the bitter EOL for this one.
  64.         bsr.s   getcmd          ; get comment in a4
  65.         cmp.l   #80,d0          ; we allow a zero length string here.
  66.         bls.s   setcom
  67.         lea     toolong(pc),a0
  68.         bra.s   error
  69. setcom: move.l  a0,d2           ; ptr to comment in a4
  70.         ;
  71.         ; Ok, we have the parameters, now let's set the comment.
  72.         ;
  73.         jsr     _LVOSetComment(a6)
  74.         tst.l   d0
  75.         bne.s   okokokok
  76.         lea     nocando(pc),a0
  77.         bra.s   error
  78. okokokok:
  79.         moveq.l #0,d4
  80.         bra.s   exit
  81.  
  82.         ; Get command - return ptr to start of string in a0
  83.         ; This searches for quotes, etc.
  84.         ; Enter with d7.b = default terminator character for command
  85.         ;
  86.         ; Returns a2 pointing to next unread character
  87.         ; a0 points to start of arg
  88.         ; d0 contains character count of arg
  89.         ; d6 contains last character read
  90. getcmd: 
  91.         moveq.l #0,d0           ; zero command line count
  92. skipbl:
  93.         move.b  (a2)+,d6
  94.         cmp.b   #' ',d6         ; skip leading blanks
  95.         beq.s   skipbl
  96.         cmp.b   #$0a,d6         ; empty string?
  97.         bne.s   chkquote        ; null string
  98.         lea.l   null(pc),a0     ; return ptr to null
  99.         rts
  100. chkquote:
  101.         move.l  a2,a0           ; setup return pointer
  102.         cmp.b   #'"',d6         ; check for quoted string
  103.         bne.s   notquoted
  104.         move.b  d6,d7           ; change default terminator
  105.         bra.s   scan
  106. notquoted:
  107.         subq.l  #1,a0
  108. scan:
  109.         addq    #1,d0
  110.         move.b  (a2)+,d6
  111.         cmp.b   #$0a,d6         ; exit on LF
  112.         beq.s   zapch
  113.         cmp.b   d6,d7
  114.         bne.s   scan
  115. zapch:  clr.b   -1(a2)          ; null terminate
  116.         rts
  117.         
  118. ;
  119. ; Error Routines - enter with a0 pointing to error message.
  120. ;
  121. error:
  122.         moveq.l #0,d3           ; clear upper bytes
  123.         move.l  d3,d4
  124.         move.b  (a0)+,d4        ; get return code
  125.         move.b  (a0)+,d3        ; get length
  126.         move.l  a0,d2           ; address
  127.         jsr     _LVOOutput(a6)
  128.         move.l  d0,d1
  129.         jsr     _LVOWrite(a6)
  130. exit:   move.l  a6,a1
  131.         move.l  _AbsExecBase,a6
  132.         jsr     _LVOCloseLibrary(a6)
  133.         move.l  d4,d0
  134.         rts
  135.  
  136. DOSName:        dc.b    "dos.library"
  137. null:           dc.b    0
  138.         ;
  139.         ;
  140.         ; Format of error numbers here is
  141.         ; Return code, length, string.
  142.         ;
  143.         ;
  144. usage:          dc.b    0,37,"Usage: Filenote <filename> <comment>",$0a
  145. toolong:        dc.b    20,18,"Comment too long.",$0a
  146. nocando:        dc.b    20,20,"Can't set filenote.",$0a
  147.